<style scoped>
  .weui-form-preview__hd label, .weui-form-preview__hd em {
    font-size: .9em !important;
  }
  .weui-loadmore_line .weui-loadmore__tips {
    background-color: #eee;
  }
  .rj-cell.max span{
    font-size: 16px;
    padding-right: 20px;
  }
  .rj-cell label {
    color: #333;
    font-size: 14px;
    width: 44%;
    display: inline-block;
    padding: 5px 3%;
    text-align: right;
  }
  .rj-cell span {
    font-size: 14px;
    color: #333;
    display: inline-block;
    width: 50%;
  }
  .rj-cell.note label{
    float: left;
  }
  .rj-cell.note span{
    width: 80%;
    display: inline-block;
  }
  .weui-cells {
    margin-top: 0;
  }
  .weui-cells_form {
    background: #fbfbfb;
  }
  .weui-cell {
    background: #fff;
  }
  .weui-cells__title {
    text-align: left;
  }
  .oitem {
    padding: 3px;
  }
  .hide {
    display: none;
  }
  #acts {
    font-size: 0;
  }
  #acts span {
    font-size: 14px;
  }
  .halfbtn {
    display: inline-block;
    width: 49%;
  }
  h2 {font-size: 17px;color: #000000; display : inline}
  input[readonly='readonly']{
    background: #ffffff;
    color: #ccc;
  }
</style>
<template>
  <div>
    <div style="height: 50px; line-height: 50px; background: #f7f7f7; text-align: center; font-size: 16px; border-bottom: 1px solid #bdbbbc; position: relative">
      结算确认
      <a href="javascript:;" @click="$router.back(-1)" style="position: absolute; left: 10px; top: 8px">
        <img src="../../assets/back.png" style="width: 20px" />
      </a>
    </div>
    <div class="weui-cells weui-cells_form">
      <!--      <form action="/sales/Sellform!saveOrUpdate .action?openid=${openid}" method="post" id="formid">-->
      <form action="/api/sellform/add" method="post"  id="formid">
        <input type="hidden"  name="orderguid" :value="guid" />
        <div class="weui-cells__title">销售订单信息

          <p id="acts1" style="float: right;color: #1aad19;">
            <!--<span id="addItem" style="padding-right: 5px;">添加</span>-->
          </p>
        </div>
        <div class="weui-cell">
          <div class="weui-cell__hd"><label for="productguid1" class="weui-label">订单编号:</label></div>
          <div class="weui-cell__bd">
            <input class="weui-input" type="text" readonly id="sellcode" :value="formData.sellcode"  >
          </div>
        </div>

        <div class="weui-cell">
          <div class="weui-cell__hd"><label for="productguid1" class="weui-label">申请人:</label></div>
          <div class="weui-cell__bd">
            <input class="weui-input" type="text" readonly id="applyname" :value="formData.applyname"  >
          </div>
        </div>

        <div class="weui-cell">
          <div class="weui-cell__hd"><label for="productguid1" class="weui-label">客户:</label></div>
          <div class="weui-cell__bd">
            <input class="weui-input" type="text" readonly id="customername" :value="formData.customername"  >
          </div>
        </div>

        <!--<div class="weui-cell">-->
          <!--<div class="weui-cell__hd"><label for="productguid1" class="weui-label">提交人:</label></div>-->
          <!--<div class="weui-cell__bd">-->
            <!--<input class="weui-input" type="text" readonly id="operatorname" :value="formData.operatorname"   >-->
          <!--</div>-->
        <!--</div>-->

        <div class="oitem"  v-for="(item, index) in data" :key="item.guid">
          <input type="hidden"  :name="appand(index,'guid')" :value="guid" />

          <div class="weui-cells__title">货品明细 <h2 >({{index + 1}})</h2>
            <input type="hidden"  :name="appand(index,'guid')" :value="item.guid" />
            <input type="hidden"  name="orderguid" :value="guid" />
            <p id="acts" style="float: right;color: #1aad19;">
              <!--<span id="addItem" style="padding-right: 5px;">添加</span>-->
            </p>
          </div>
          <div class="weui-cell">
            <div class="weui-cell__hd"><label for="productguid1" class="weui-label">产品</label></div>
            <div class="weui-cell__bd">
              <input class="weui-input" type="text" readonly id="productguid1" :value="item.productname"  placeholder="请选择品种">
            </div>
          </div>
          <div class="weui-cell">
            <div class="weui-cell__hd"><label for="spguid1" class="weui-label">规格</label></div>
            <div class="weui-cell__bd">
              <input class="weui-input" type="text" readonly id="spguid1" :value="item.spname"  placeholder="请选择规格">
            </div>
          </div>





          <div class="weui-cell">
            <div class="weui-cell__hd"><label class="weui-label">净重(吨)</label></div>
            <div class="weui-cell__bd">
              <input class="weui-input" type="number" id="weight1"  :name="appand(index,'unloadweight')" placeholder="请输入订单净重">
            </div>
          </div>

          <div class="weui-cell">
            <div class="weui-cell__hd"><label class="weui-label">包装重量(kg)</label></div>
            <div class="weui-cell__bd">
              <input class="weui-input" type="number" id="packweight" :name="appand(index,'packweight')"   placeholder="请输入扣除包装重量">

            </div>
          </div>

          <div class="weui-cell">
            <div class="weui-cell__hd"><label class="weui-label">扣杂率</label></div>
            <div class="weui-cell__bd">
              <input class="weui-input" type="number" id="DeductRate" :name="appand(index,'deductrate')"    placeholder="请输入扣杂率">
            </div>
          </div>

        </div>









        <div class="weui-btn-area">
          <a class="weui-btn weui-btn_primary halfbtn subbtn" href="javascript:" @click="send">提交</a>
          <!--<a class="weui-btn weui-btn_primary halfbtn" href="javascript:"  @click="$router.back(-1)" id="sub">取消</a>-->
        </div>
      </form>
    </div>
  </div>
</template>

<script>

  export default {
    name: 'SellToSure',
    data () {
      return {
        guid : "",
        nodeid: '',
        data: [],
        formData:{},
        wxConf:{},
        postParams: {
          pageSize: "1"
        },
        loading: false,
        showLoadIcon: false,
        showNomore: false,
        wrapperHeight: 0,
        userCode: localStorage.userCode || '',//用户code
        images: {
          localId: [], //已选择的本地图片
          serverId: [] //微信服务器返回的mediaId
        },
        saveImages: {
          previewImageList: [], //预览大图数组,
          previewThumbList: [], //预览缩略图数组
          saveImageList: [], //预览大图数组//保存图片
        },
        uploadPath: '' //图片上传的路径：为空时，默认下载到当前项目的/mcupload路径下

      }
    },
    mounted () {
      this.guid = this.$route.query.guid;
      this.nodeid = this.$route.query.nodeid;
      this.axios({
        method: 'get',
        url: '/sales/Sellitem!getItem.action',
        params:  {sellguid:this.guid}
      }).then(response => {
        this.data = response.data.info;
      });
      this.loadSellForm(this.guid);
    },
    methods: {
      send: function() {
        //防止重复提交
        $('.subbtn').attr("disabled",true).css("pointer-events","none");

        this.axios({
          method: 'post',
          responseType: 'json',
          headers: { "Content-Type": "application/x-www-form-urlencoded;charset=UTF-8" },
          url: '/sales/Sellitem!orderSure.action?openid=' + localStorage.openid + '&nodeid=' + this.nodeid,
          params: this.serialize2Obj($("#formid").serializeArray())
        }).then(response => {
          //恢复提交按钮可点击
          $('.subbtn').attr('disabled', false).css("pointer-events","auto");

          if(response.data.info == "ok"){

            this.toastText('操作成功!');
          }else{
            this.toastError('操作失败!');

          }
          this.$router.push({name: 'Sellform'});
        }).catch(function (error) {
          //恢复提交按钮可点击
          $('.subbtn').attr('disabled', false).css("pointer-events","auto");
          this.toastError('系统错误');
        });
      },
      serialize2Obj: function (data) {
        var obj = {};
        $.each(data,function(i,v){
          obj[v.name] = v.value;
        })
        return obj;
      },
      appand:function (index,key){
        return "sellitems[" + index + "]." + key;
      },
      loadSellForm:function (guid){
        this.axios({
          method: 'get',
          url: '/sales/Sellform!get.action',
          params:  {guid:guid}
        }).then(response => {
          console.log( response.data);
          this.formData = response.data.info;
        });
      }

    }

  }
</script>


